package com.wolfcode.customer.service.impl;

import java.util.List;

import com.wolfcode.common.utils.DateUtils;
import com.wolfcode.common.utils.SecurityUtils;
import com.wolfcode.customer.domain.info.CustomerInfo;
import com.wolfcode.customer.domain.info.CustomerVisitInfo;
import com.wolfcode.customer.domain.info.LinkmanInfo;
import com.wolfcode.customer.domain.vo.CustomerVisitVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wolfcode.customer.mapper.CustomerVisitMapper;
import com.wolfcode.customer.domain.CustomerVisit;
import com.wolfcode.customer.service.ICustomerVisitService;
import org.springframework.util.Assert;

/**
 * 拜访信息Service业务层处理
 *
 * @author sitia
 * @date 2022-12-09
 */
@Service
public class CustomerVisitServiceImpl implements ICustomerVisitService
{
    @Autowired
    private CustomerVisitMapper customerVisitMapper;

    /**
     * 查询拜访信息
     *
     * @param id 拜访信息主键
     * @return 拜访信息
     */
    @Override
    public CustomerVisit selectCustomerVisitById(Long id)
    {
        return customerVisitMapper.selectCustomerVisitById(id);
    }

    /**
     * 查询拜访信息列表
     *
     * @param customerVisit 拜访信息
     * @return 拜访信息
     */
    @Override
    public List<CustomerVisitInfo> selectCustomerVisitList(CustomerVisit customerVisit)
    {
        return customerVisitMapper.selectCustomerVisitList(customerVisit);
    }

    /**
     * 新增拜访信息
     *
     * @param customerVisit 拜访信息
     * @return 结果
     */
    @Override
    public int insertCustomerVisit(CustomerVisitVo customerVisit)
    {
        Assert.notNull(customerVisit,"非法请求");
        Assert.notNull(customerVisit.getCustomerId(),"客户不能为空");
        Assert.notNull(customerVisit.getLinkmanId(),"请选择联系人");
        Assert.notNull(customerVisit.getVisitDate(),"拜访时间不能为空");
        Assert.notNull(customerVisit.getVisitType(),"拜访方法不能为空");
        CustomerVisit visit = new CustomerVisit();
        BeanUtils.copyProperties(customerVisit,visit);
        visit.setInputTime(DateUtils.getNowDate());
        visit.setInputUser(SecurityUtils.getUsername());
        return customerVisitMapper.insertCustomerVisit(visit);
    }

    /**
     * 修改拜访信息
     *
     * @param customerVisit 拜访信息
     * @return 结果
     */
    @Override
    public int updateCustomerVisit(CustomerVisit customerVisit)
    {
        return customerVisitMapper.updateCustomerVisit(customerVisit);
    }

    /**
     * 批量删除拜访信息
     *
     * @param ids 需要删除的拜访信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerVisitByIds(Long[] ids)
    {
        return customerVisitMapper.deleteCustomerVisitByIds(ids);
    }

    /**
     * 删除拜访信息信息
     *
     * @param id 拜访信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerVisitById(Long id)
    {
        return customerVisitMapper.deleteCustomerVisitById(id);
    }

    @Override
    public List<CustomerInfo> getCustomer() {
        return customerVisitMapper.getAllCustomer();
    }

    @Override
    public  List<LinkmanInfo> getLinemanByCustomer(Long id) {
        Assert.notNull(id,"未输入id");
        return customerVisitMapper.selectLinkmanByCustomerId(id);
    }
}
